# coding : utf-8
import requests,json,time,random

import requests,json,time,random
word = input('''你好，我是你的私人助理吴小枫。请输入你的第0个问题，格式如：XX有哪些相关词汇？然后点击回车
>''')
res = word.find('有哪些相关词汇')
while res<=0:
    time.sleep(1)
    word = input('''请按照正确格式输入，如：牛肉有哪些相关词汇？记得要一字不差奥！然后点击回车
>''')
    res = word.find('有哪些相关词汇')
else:
    url1 = 'http://ictclas.nlpir.org/nlpir/index/getAllContentNew.do'
    data1 = {'type':'all','content':word}
    r1 = requests.post(url1,data1)
    dividewords = json.loads(r1.text)['dividewords']
    dividewords = dividewords.split(' ')
    newwords=[]
    cixing = []
    for x in dividewords:
        if x == dividewords[-1]:
            continue
        else:
            singleword = x.split('/')
            newwords.append(singleword[0])
            cixing.append(singleword[1])
    newlist = '/'.join(newwords)
    dict = {'n':'名词','nr':'人名','nr1':'汉语姓氏','nr2':'汉语名字','nrj':'日语人名','nrf':'音译人名','ns':'地名','nsf':'音译地名','nt':'机构团体名','nz':'其它专名','nl':'名词性惯用语','ng':'名词性语素',
't':'时间词','tg':'时间词性语素','s':'处所词','f':'方位词',
'v':'动词','vd':'副动词','vn':'名动词','vshi':'动词“是”','vyou':'动词“有”','vf':'趋向动词','vx':'形式动词','vi':'不及物动词（内动词）','vl':'动词性惯用语','vg':'动词性语素',
'a':'形容词','ad':'副形词','an':'名形词','ag':'形容词性语素','al':'形容词性惯用语','b':'区别词','':'','bl':'区别词性惯用语','z':'状态词',
'r':'代词','rr':'人称代词','rz':'指示代词','rzt':'时间指示代词','rzs':'处所指示代词','rzv':'谓词性指示代词','ry':'疑问代词','ryt':'时间疑问代词','rys':'处所疑问代词','ryv':'谓词性疑问代词','rg':'代词性语素',
'm':'数词','mq':'数量词','q':'量词','d':'副词','p':'介词','pba':'介词“把”','pbei':'介词“被”','c':'连词','cc':'并列连词',
'u':'助词','uzhe':'着','ule':'了，喽','uguo':'过','ude1':'的','ude2':'地','ude3':'得','usuo':'所','udeng':'等，等等，云云','uyy':'一样，一般，似的，般','udh':'的话','uls':'来讲，来说，而言，说来','uzhi':'之','ulian':'连',
'e':'叹词','y':'语气词','o':'拟声词','h':'前缀','k':'后缀','x':'字符串','xe':'Email字符串','xs':'微博会话分隔符','xm':'表情符合','xu':'网址URL',
'w':'标点符号','wkz':'左括号','wky':'右括号','wyz':'左引号','wj':'句号','ww':'问号','wt':'叹号','wd':'逗号','wf':'分号','wn':'顿号','wm':'冒号','ws':'省略号','wp':'破折号','wb':'百分号千分号','wh':'单位符号'
}
    time.sleep(1)
    print('\n我先把你的话做了分词：'+newlist+'。')
    cixinglist = ''
    for y in cixing:
        cixinglist = cixinglist+dict[y]+'/'
    time.sleep(2)
    print('它们的词性分别是：'+cixinglist+'。')
    time.sleep(2)
    print('其中，我判断'+newwords[0]+'是一个'+dict[cixing[0]]+'，你问我的是它的相关词汇有哪些对吗？')
    url='http://ictclas.nlpir.org/nlpir/index6/getWord2Vec.do'
    data={'content': newwords[0]}
    r = requests.post(url,data)
    other=json.loads(r.text)
    time.sleep(1)
    print ('\n我想了想和“'+newwords[0]+'”相关的词汇，至少还有：\n')
    time.sleep(1)
    f=0
    for i in other['w2vlist']:
        f=f+1
        word2 = i.split(',')
        print ('('+str(f)+')'+word2[0]+'，其相关度为'+word2[1])
        time.sleep(1)











